package design.simdi.code.final_paper.site.panels;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxFallbackButton;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;

/**
 * 
 * @author Marius Dumitriu - (Jun 25, 2010 - 6:11:58 PM)
 * 
 */
public abstract class OneButtonPanel extends PagePanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private AjaxFallbackButton back;
	@SuppressWarnings("unchecked")
	private Form form;

	public OneButtonPanel(String id, IModel<?> model) {
		super(id, model);
	}

	public OneButtonPanel(String id) {
		super(id);
	}

	@SuppressWarnings("unchecked")
	public void panelInit() {
		setOutputMarkupId(true);

		form = new Form("form");
		add(form);
		back = new AjaxFallbackButton("cancel", form) {

			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
				onCANCELButtonSubmit(target);
			}
		};
		form.add(back);

	}

	@SuppressWarnings("unchecked")
	public void setForm(Form form) {
		this.form = form;
	}

	@SuppressWarnings("unchecked")
	public Form getForm() {
		return form;
	}

	public void setBack(AjaxFallbackButton back) {
		this.back = back;
	}

	public AjaxFallbackButton getBack() {
		return back;
	}

	public abstract void onCANCELButtonSubmit(AjaxRequestTarget target);

}
